example: Port to gtk_application_set_accels_for_action
authorMatthias Clasen <mclasen@redhat.com>
Thu, 17 Apr 2014 18:36:33 +0000 (11:36 -0700)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 18 Apr 2014 02:55:38 +0000 (22:55 -0400)
Instead of hardcoding an accelerator in the ui file, use
gtk_application_set_accels_for_action.

15 files changed:
docs/reference/gtk/getting_started.xml
examples/application10/app-menu.ui
examples/application10/exampleapp.c
examples/application4/app-menu.ui
examples/application4/exampleapp.c
examples/application5/app-menu.ui
examples/application5/exampleapp.c
examples/application6/app-menu.ui
examples/application6/exampleapp.c
examples/application7/app-menu.ui
examples/application7/exampleapp.c
examples/application8/app-menu.ui
examples/application8/exampleapp.c
examples/application9/app-menu.ui
examples/application9/exampleapp.c

index f271e66b42f483fa0bd993d879ac31fef7b12a6a..5ac4ca573a35dcf66d04e07e3401f13783914b40 100644 (file)
@@ -605,12 +605,16 @@ example_app_startup (GApplication *app)
 {
   GtkBuilder *builder;
   GMenuModel *app_menu;
+  const gchar *quit_accels[2] = { "&lt;Ctrl&gt;Q", NULL };
 
   G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
 
   g_action_map_add_action_entries (G_ACTION_MAP (app),
                                    app_entries, G_N_ELEMENTS (app_entries),
                                    app);
+  gtk_application_set_accels_for_action (GTK_APPLICATION (app),
+                                         "app.quit",
+                                         quit_accels);
 
   builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
   app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
@@ -633,7 +637,7 @@ example_app_class_init (ExampleAppClass *class)
       <para>Our preferences menu item does not do anything yet,
       but the Quit menu item is fully functional. Note that it
       can also be activated by the usual Ctrl-Q shortcut. The
-      shortcut was specified in the ui file.
+      shortcut was added with gtk_application_set_accels_for_action().
       </para>
 
       <para>The application menu looks like this:</para>
index b0eddb65e5f8287052b765eaf912c7465cc2d379..e1e131cfca8036f6341724596293db0b5858ff3e 100644 (file)
@@ -12,7 +12,6 @@
       <item>
         <attribute name="label" translatable="yes">_Quit</attribute>
         <attribute name="action">app.quit</attribute>
-        <attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
       </item>
     </section>
   </menu>
index 1bc6ce85ee2acf5d90ee2debde892ac88a0f6d6c..66e85793f8c39cdf16acc009e009146b2df07b8d 100644 (file)
@@ -53,12 +53,16 @@ example_app_startup (GApplication *app)
 {
   GtkBuilder *builder;
   GMenuModel *app_menu;
+  const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
 
   G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
 
   g_action_map_add_action_entries (G_ACTION_MAP (app),
                                    app_entries, G_N_ELEMENTS (app_entries),
                                    app);
+  gtk_application_set_accels_for_action (GTK_APPLICATION (app),
+                                         "app.quit",
+                                         quit_accels);
 
   builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
   app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
index b0eddb65e5f8287052b765eaf912c7465cc2d379..e1e131cfca8036f6341724596293db0b5858ff3e 100644 (file)
@@ -12,7 +12,6 @@
       <item>
         <attribute name="label" translatable="yes">_Quit</attribute>
         <attribute name="action">app.quit</attribute>
-        <attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
       </item>
     </section>
   </menu>
index ea2455754051bc70904a571a896935117ee95ef6..e83f139c263c96a1bf809ec1c61eb4fd04d45447 100644 (file)
@@ -46,12 +46,16 @@ example_app_startup (GApplication *app)
 {
   GtkBuilder *builder;
   GMenuModel *app_menu;
+  const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
 
   G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
 
   g_action_map_add_action_entries (G_ACTION_MAP (app),
                                    app_entries, G_N_ELEMENTS (app_entries),
                                    app);
+  gtk_application_set_accels_for_action (GTK_APPLICATION (app),
+                                         "app.quit",
+                                         quit_accels);
 
   builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
   app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
index b0eddb65e5f8287052b765eaf912c7465cc2d379..e1e131cfca8036f6341724596293db0b5858ff3e 100644 (file)
@@ -12,7 +12,6 @@
       <item>
         <attribute name="label" translatable="yes">_Quit</attribute>
         <attribute name="action">app.quit</attribute>
-        <attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
       </item>
     </section>
   </menu>
index ea2455754051bc70904a571a896935117ee95ef6..e83f139c263c96a1bf809ec1c61eb4fd04d45447 100644 (file)
@@ -46,12 +46,16 @@ example_app_startup (GApplication *app)
 {
   GtkBuilder *builder;
   GMenuModel *app_menu;
+  const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
 
   G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
 
   g_action_map_add_action_entries (G_ACTION_MAP (app),
                                    app_entries, G_N_ELEMENTS (app_entries),
                                    app);
+  gtk_application_set_accels_for_action (GTK_APPLICATION (app),
+                                         "app.quit",
+                                         quit_accels);
 
   builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
   app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
index b0eddb65e5f8287052b765eaf912c7465cc2d379..e1e131cfca8036f6341724596293db0b5858ff3e 100644 (file)
@@ -12,7 +12,6 @@
       <item>
         <attribute name="label" translatable="yes">_Quit</attribute>
         <attribute name="action">app.quit</attribute>
-        <attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
       </item>
     </section>
   </menu>
index 36ef1525937957a0c22b381c39877412fdc83693..d0e07744535a2ff8d16defcc4d8c2063f9a82e49 100644 (file)
@@ -53,12 +53,16 @@ example_app_startup (GApplication *app)
 {
   GtkBuilder *builder;
   GMenuModel *app_menu;
+  const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
 
   G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
 
   g_action_map_add_action_entries (G_ACTION_MAP (app),
                                    app_entries, G_N_ELEMENTS (app_entries),
                                    app);
+  gtk_application_set_accels_for_action (GTK_APPLICATION (app),
+                                         "app.quit",
+                                         quit_accels);
 
   builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
   app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
index b0eddb65e5f8287052b765eaf912c7465cc2d379..e1e131cfca8036f6341724596293db0b5858ff3e 100644 (file)
@@ -12,7 +12,6 @@
       <item>
         <attribute name="label" translatable="yes">_Quit</attribute>
         <attribute name="action">app.quit</attribute>
-        <attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
       </item>
     </section>
   </menu>
index 1bc6ce85ee2acf5d90ee2debde892ac88a0f6d6c..66e85793f8c39cdf16acc009e009146b2df07b8d 100644 (file)
@@ -53,12 +53,16 @@ example_app_startup (GApplication *app)
 {
   GtkBuilder *builder;
   GMenuModel *app_menu;
+  const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
 
   G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
 
   g_action_map_add_action_entries (G_ACTION_MAP (app),
                                    app_entries, G_N_ELEMENTS (app_entries),
                                    app);
+  gtk_application_set_accels_for_action (GTK_APPLICATION (app),
+                                         "app.quit",
+                                         quit_accels);
 
   builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
   app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
index b0eddb65e5f8287052b765eaf912c7465cc2d379..e1e131cfca8036f6341724596293db0b5858ff3e 100644 (file)
@@ -12,7 +12,6 @@
       <item>
         <attribute name="label" translatable="yes">_Quit</attribute>
         <attribute name="action">app.quit</attribute>
-        <attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
       </item>
     </section>
   </menu>
index 1bc6ce85ee2acf5d90ee2debde892ac88a0f6d6c..66e85793f8c39cdf16acc009e009146b2df07b8d 100644 (file)
@@ -53,12 +53,16 @@ example_app_startup (GApplication *app)
 {
   GtkBuilder *builder;
   GMenuModel *app_menu;
+  const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
 
   G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
 
   g_action_map_add_action_entries (G_ACTION_MAP (app),
                                    app_entries, G_N_ELEMENTS (app_entries),
                                    app);
+  gtk_application_set_accels_for_action (GTK_APPLICATION (app),
+                                         "app.quit",
+                                         quit_accels);
 
   builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
   app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
index b0eddb65e5f8287052b765eaf912c7465cc2d379..e1e131cfca8036f6341724596293db0b5858ff3e 100644 (file)
@@ -12,7 +12,6 @@
       <item>
         <attribute name="label" translatable="yes">_Quit</attribute>
         <attribute name="action">app.quit</attribute>
-        <attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
       </item>
     </section>
   </menu>
index 1bc6ce85ee2acf5d90ee2debde892ac88a0f6d6c..66e85793f8c39cdf16acc009e009146b2df07b8d 100644 (file)
@@ -53,12 +53,16 @@ example_app_startup (GApplication *app)
 {
   GtkBuilder *builder;
   GMenuModel *app_menu;
+  const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
 
   G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
 
   g_action_map_add_action_entries (G_ACTION_MAP (app),
                                    app_entries, G_N_ELEMENTS (app_entries),
                                    app);
+  gtk_application_set_accels_for_action (GTK_APPLICATION (app),
+                                         "app.quit",
+                                         quit_accels);
 
   builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
   app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));